using System;
using System.Web.UI;
using PHSRAG.Insight21.Context;
using PHSRAG.Insight21.Policy;
using PHSRAG.Utility;

namespace PHSRAG.Insight21
{
    public partial class LogoutPage : Page
    {
        #region Event Handlers

        protected void OnPageLoad(object sender, EventArgs e)
        {
            try
            {
                if (Page.Session != null && Page.Session[Names.CachePolicyKey] == null)
                {
                    ICachePolicy cachePolicy = (ICachePolicy) Page.Session[Names.CachePolicyKey];
                    UserContext userContext = cachePolicy.GetCachedObject(UserContext.CacheKey) as UserContext;
                }

                Session.Abandon();
            }
            catch
            {
            }
            if (Settings.GetKeyValue("SingleSignOnEnabled", false))
            {
                Response.Redirect("~/login/Logout.html" + "?" + Request.QueryString["message"], true);
            }
            else
            {
                string queryString = string.Empty;

                if (!string.IsNullOrEmpty(Request.QueryString["message"]))
                {
                    queryString = "?message=" + Request.QueryString["message"];    
                }

                Response.Redirect(Settings.GetKeyValue("Header.LoginURL", "") + queryString, true);
            }
        }

        #endregion

        #region Web Form Designer generated code

        protected override void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.OnPageLoad);
        }

        #endregion
    }
}